package chances.epg.user.service.rdb;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Service;

import chances.epg.entity.user.ScheduleOrder;
import chances.epg.user.service.ScheduleOrderService;

@Service("interactionService")
public class RdbScheduleOrderService extends BaseDao implements ScheduleOrderService {

	@Override
	public void add(ScheduleOrder userSub) {
		Map<String, Object> paramsMap = new HashMap<String, Object>();
		paramsMap.put("obj", userSub);
		try {
			this.insert("insertSubscription", paramsMap);
		} finally {
			paramsMap.clear();
			paramsMap = null;
		}
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<ScheduleOrder> listScheduleOrder(String userId, String stbNo) {
		Map<String, Object> paramsMap = new HashMap<String, Object>();
		paramsMap.put("userId", userId);
		paramsMap.put("stbNo", stbNo);
		try {
			return (List<ScheduleOrder>) this.queryForList("selectSubscriptionByStbNo", paramsMap);
		} finally {
			paramsMap.clear();
			paramsMap = null;
		}
		
	}

	@Override
	public void cancel(String userId, String code) {
		Map<String, Object> paramsMap = new HashMap<String, Object>();
		paramsMap.put("userId", userId);
		paramsMap.put("code", code);
		try {
			this.delete("deleteSubscription", paramsMap);
		} finally {
			paramsMap.clear();
			paramsMap = null;
		}
		
	}

	@Override
	public void deleteSub(String userId, String[] codes, String stbNo) {
		Map<String, Object> paramsMap = new HashMap<String, Object>();
		paramsMap.put("userId", userId);
		paramsMap.put("codes", codes);
		paramsMap.put("stbNo", stbNo);
		try {
			this.delete("delSubByUserAndCodes", paramsMap);
		} finally {
			paramsMap.clear();
			paramsMap = null;
		}
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<ScheduleOrder> listPlayingScheduleOrder() {
		Map<String, Object> paramsMap = new HashMap<String, Object>();
		try {
			return (List<ScheduleOrder>) this.queryForList("selectPlayingSubscription", paramsMap);
		} finally {
			paramsMap.clear();
			paramsMap = null;
		}
		
	}

	@Override
	public void updateListScheduleOrder(List<Long> subscrList) {
		
		Map<String, Object> paramsMap = new HashMap<String, Object>();
		paramsMap.put("subIds", subscrList);
		try {
			this.update("updateListSubscription", paramsMap);
		} finally {
			paramsMap.clear();
			paramsMap = null;
		}
	}

}
